package com.amigo.online.common.util;

import java.util.Random;
import java.util.UUID;

import org.apache.commons.lang3.RandomStringUtils;

/**
 * 字符串工具类
 * @author amigo
 *
 */
public class StringUtils extends org.apache.commons.lang3.StringUtils {

	public static int randomInt(int from,int to) {
		Random r = new Random();
        return from + r.nextInt(to - from);
	}
	
	/**
	 * 生成手机验证码
	 * @param charCount
	 * @return
	 */
	public static String generateVerificationCode(int charCount) {
		String charValue = "";
        for (int i = 0; i < charCount; i++) {
            char c = (char) (randomInt(0, 10) + '0');
            charValue += String.valueOf(c);
        }
        return charValue;
	}
	
	public static String generateAccountString() {
		long nowMilliSeconds = System.currentTimeMillis();
        long nowSeconds = nowMilliSeconds / 1000;
        String temp=RandomStringUtils.randomAlphanumeric(6);
        String account = "amigo"+nowSeconds+temp;
        return account.toLowerCase();
	}
	
	/**
     * 获取 UUID（32位）
     */
    public static String createUUID() {
        return UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
    }
    
    /**
     * 获取 token;
     */
    public static String createUserToken() {
        return "AMIGOTOKEN"+UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
    }
}
